#!/usr/bin/env python3

import torch
from safetensors import safe_open
import os
import sys

def inspect_adapter_model(file_path):
    """检查adapter_model.safetensors文件的内容"""
    print(f"检查文件: {file_path}")
    
    if not os.path.exists(file_path):
        print(f"文件不存在: {file_path}")
        return
    
    # 打开safetensors文件
    tensors = {}
    with safe_open(file_path, framework="pt", device="cpu") as f:
        print("\n文件中的键（参数名称）:")
        keys = f.keys()
        for key in keys:
            print(f"  - {key}")
            
        print(f"\n总参数数量: {len(keys)}")
        
        # 获取一些参数的形状信息
        print("\n参数形状信息:")
        for i, key in enumerate(list(keys)[:10]):  # 只显示前10个
            tensor = f.get_tensor(key)
            print(f"  {key}: {list(tensor.shape)}")
            
        if len(keys) > 10:
            print(f"  ... 还有 {len(keys) - 10} 个参数")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("使用方法: python inspect_adapter.py <adapter_model.safetensors文件路径>")
        sys.exit(1)
        
    file_path = sys.argv[1]
    inspect_adapter_model(file_path)
